# 导包
import unittest
from api.goods import GoodsAPI

# 创建测试类
class TestGoodsAPI(unittest.TestCase):
    # 初始化
    # 商品分类id
    id111 = None
    # 商品id
    id222 = None

    # 前置处理
    def setUp(self) -> None:
        # 实例化接口类
        self.goods_api = GoodsAPI()

    # 后置处理
    def tearDown(self) -> None:
        pass

    # 获取商品分类
    def test01_list(self):
        response = self.goods_api.get_list()
        print(response.json())
        # 提取商品分类id并保存至类的属性
        TestGoodsAPI.id111 = response.json()[1].get("id")

    # 获取分类下商品
    def test02_under(self):
        response = self.goods_api.get_under(TestGoodsAPI.id111)
        print(response.json())
        # 提取商品id并保存至类的属性
        TestGoodsAPI.id222 = response.json()[0].get("id")

    # 获取商品详情
    def test03_info(self):
        response = self.goods_api.get_info(TestGoodsAPI.id222)
        print(response.json())